package com.zz.mapper;

import com.zz.domain.ExamSubmission;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ExamSubmissionMapper {
    @Insert("INSERT INTO exam_submissions(machine_id, submit_time, exam_id, json_data, file_path, upload_status, upload_time) " +
            "VALUES(#{machineId}, #{submitTime}, #{examId}, #{jsonData}, #{filePath}, #{uploadStatus}, #{uploadTime})")
    @Options(useGeneratedKeys = true, keyProperty = "submissionId")
    int insert(ExamSubmission examSubmission);

    @Update("UPDATE exam_submissions SET upload_status=#{uploadStatus}, upload_time=#{uploadTime} " +
            "WHERE submission_id=#{submissionId}")
    int update(ExamSubmission examSubmission);

    @Select("SELECT * FROM exam_submissions WHERE exam_id = #{examId}")
    List<ExamSubmission> selectByExamId(String examId);

    @Select("SELECT * FROM exam_submissions WHERE upload_status = 'pending'")
    List<ExamSubmission> selectPendingSubmissions();

    @Select("SELECT * FROM exam_submissions WHERE machine_id = #{machineId}")
    List<ExamSubmission> selectByMachineId(String machineId);

    @Select("SELECT * FROM exam_submissions WHERE exam_id = #{examId} AND machine_id = #{machineId}")
    ExamSubmission selectByExamAndMachine(@Param("examId") String examId,
                                          @Param("machineId") String machineId);
}